const app = getApp();
Page({
  data: {
    languages: ['中文', 'English'],
    selectedLanguage: '中文',
    banners: [],
    products: [],
    videos:[],
    details: []
  },
  
  onSearch(e) {
    const value = e.detail.value;
    // 可在此实现商品筛选搜索逻辑
    wx.showToast({title: `搜索：${value}`, icon: 'none'});
  },
  onLoadMore() {
    // 跳转到商品列表页面
    wx.navigateTo({
      url: '/pages/productList/productList',
    });
  },
  getProducts() {
    wx.request({
      url: `${app.globalData.baseUrl}/product/list?pageNum=1&pageSize=6`,
      method: 'GET',
      success: (res) => {
        console.log('llll',res.data)
        // 截取前9条
        let list = res.data.rows.slice(0, 6);
        this.setData({ products: list });
      }
    });
  },
  getVideos() {
    wx.request({
      url: `${app.globalData.baseUrl}/video/list?pageNum=1&pageSize=10000`,
      method: 'GET',
      success: (res) => {
        console.log('llll',res.data)
        // 截取前9条
        this.setData({ videos: res.data.rows });
      }
    });
  },
  onProductTap(item) {
    wx.navigateTo({
      url: `/pages/details/details?productId=${18}`,
    });
  },
  onLoad() {
    
    const baseUrl = app.globalData.baseUrl;
    this.getProducts();
    this.getVideos()
    // 使用 baseUrl 发起请求...
  }
});